package com.caochenlei.tree.ufs.version1;

import java.util.Scanner;

public class UnionFindSetsTest {
    public static void main(String[] args) {
        UnionFindSets ufs = new UnionFindSets(4);
        System.out.println("初始化并查集中有：" + ufs.count() + "个分组");
        Scanner sc = new Scanner(System.in);
        while (true) {
            System.out.print("请输入第一个要合并的元素：");
            int p = sc.nextInt();
            System.out.print("请输入第二个要合并的元素：");
            int q = sc.nextInt();
            if (ufs.connected(p, q)) {
                System.out.println(p + "元素和" + q + "元素已经在同一个组中了");
                continue;
            } else {
                ufs.union(p, q);
                System.out.println("当前并查集中还有：" + ufs.count() + "个分组");
            }
        }
    }
}
